Skip to content

Add middleware e2e tests#674

Merged
notaphplover merged 23 commits intomainfrom
feat/add-middleware-e2e-tests
May 3, 2025
Merged

Add middleware e2e tests#674
notaphplover merged 23 commits intomainfrom
feat/add-middleware-e2e-tests

Conversation

@adrianmjim
Copy link
Member

No description provided.

@changeset-bot
Copy link

changeset-bot bot commented Apr 26, 2025

⚠️ No Changeset found

Latest commit: c90a6eb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Contributor

Benchmarks results:

> root@ benchmarks:http:cjs /home/runner/work/monorepo/monorepo
> pnpm run --filter "@inversifyjs/http-benchmarks" benchmarks:run:cjs


> @inversifyjs/http-benchmarks@ benchmarks:run:cjs /home/runner/work/monorepo/monorepo/packages/http/tools/http-benchmarks
> BUILD_TARGET=cjs ./bin/run-cjs.cjs

[CJS] Running benchmarks...

Express Basic Get Request
┌─────────┬───────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name                 │ Latency avg (ms) │ Latency med (ms) │ Throughput avg (req/s) │ Samples │
├─────────┼───────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼─────────┤
│ 0       │ 'currentInversifyExpress''109.732''45.266''4077.241'             │ 44981   │
│ 1       │ 'express''99.606''43.013''4517.869'             │ 49891   │
│ 2       │ 'NestJSExpress''108.139''45.118''4133.157'             │ 45638   │
└─────────┴───────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴─────────┘
currentInversifyExpress vs express Speedup: 0.902x
currentInversifyExpress vs NestJSExpress Speedup: 0.986x

Express v4 Basic Get Request
┌─────────┬────────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name                  │ Latency avg (ms) │ Latency med (ms) │ Throughput avg (req/s) │ Samples │
├─────────┼────────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼─────────┤
│ 0       │ 'currentInversifyExpress4''96.706''42.711''4655.671'             │ 51452   │
│ 1       │ 'express4''94.004''41.673''4803.871'             │ 53089   │
└─────────┴────────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴─────────┘
currentInversifyExpress4 vs express4 Speedup: 0.969x

Fastify Basic Get Request
┌─────────┬───────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name                 │ Latency avg (ms) │ Latency med (ms) │ Throughput avg (req/s) │ Samples │
├─────────┼───────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼─────────┤
│ 0       │ 'currentInversifyFastify''41.654''34.690''12058.715'            │ 121727  │
│ 1       │ 'fastify''32.477''27.244''15309.494'            │ 154217  │
│ 2       │ 'NestJSFastify''36.187''30.598''13846.184'            │ 139442  │
└─────────┴───────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴─────────┘
currentInversifyFastify vs fastify Speedup: 0.788x
currentInversifyFastify vs NestJSFastify Speedup: 0.871x

Hono Basic Get Request
┌─────────┬────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name              │ Latency avg (ms) │ Latency med (ms) │ Throughput avg (req/s) │ Samples │
├─────────┼────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼─────────┤
│ 0       │ 'currentInversifyHono''38.162''33.439''13031.935'            │ 131296  │
│ 1       │ 'hono''34.722''30.301''14373.212'            │ 144924  │
└─────────┴────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴─────────┘
currentInversifyHono vs hono Speedup: 0.907x

@github-actions
Copy link
Contributor

Benchmarks results:

> root@ benchmarks:http:cjs /home/runner/work/monorepo/monorepo
> pnpm run --filter "@inversifyjs/http-benchmarks" benchmarks:run:cjs


> @inversifyjs/http-benchmarks@ benchmarks:run:cjs /home/runner/work/monorepo/monorepo/packages/http/tools/http-benchmarks
> BUILD_TARGET=cjs ./bin/run-cjs.cjs

[CJS] Running benchmarks...

Express Basic Get Request
┌─────────┬───────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name                 │ Latency avg (ms) │ Latency med (ms) │ Throughput avg (req/s) │ Samples │
├─────────┼───────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼─────────┤
│ 0       │ 'currentInversifyExpress''112.379''45.656''3969.880'             │ 43898   │
│ 1       │ 'express''102.254''43.576''4407.125'             │ 48690   │
│ 2       │ 'NestJSExpress''111.997''45.560''3981.736'             │ 43971   │
└─────────┴───────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴─────────┘
currentInversifyExpress vs express Speedup: 0.901x
currentInversifyExpress vs NestJSExpress Speedup: 0.997x

Express v4 Basic Get Request
┌─────────┬────────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name                  │ Latency avg (ms) │ Latency med (ms) │ Throughput avg (req/s) │ Samples │
├─────────┼────────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼─────────┤
│ 0       │ 'currentInversifyExpress4''99.447''42.787''4525.137'             │ 50053   │
│ 1       │ 'express4''94.675''42.077''4767.620'             │ 52645   │
└─────────┴────────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴─────────┘
currentInversifyExpress4 vs express4 Speedup: 0.949x

Fastify Basic Get Request
┌─────────┬───────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name                 │ Latency avg (ms) │ Latency med (ms) │ Throughput avg (req/s) │ Samples │
├─────────┼───────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼─────────┤
│ 0       │ 'currentInversifyFastify''43.356''38.005''11629.959'            │ 117441  │
│ 1       │ 'fastify''33.234''28.869''14983.059'            │ 150193  │
│ 2       │ 'NestJSFastify''36.312''31.618''13728.545'            │ 138454  │
└─────────┴───────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴─────────┘
currentInversifyFastify vs fastify Speedup: 0.776x
currentInversifyFastify vs NestJSFastify Speedup: 0.847x

Hono Basic Get Request
┌─────────┬────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name              │ Latency avg (ms) │ Latency med (ms) │ Throughput avg (req/s) │ Samples │
├─────────┼────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼─────────┤
│ 0       │ 'currentInversifyHono''39.381''34.100''12694.422'            │ 128077  │
│ 1       │ 'hono''35.973''30.645''13849.297'            │ 139087  │
└─────────┴────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴─────────┘
currentInversifyHono vs hono Speedup: 0.917x

@github-actions
Copy link
Contributor

github-actions bot commented May 1, 2025

Benchmarks results:

> root@ benchmarks:http:cjs /home/runner/work/monorepo/monorepo
> pnpm run --filter "@inversifyjs/http-benchmarks" benchmarks:run:cjs


> @inversifyjs/http-benchmarks@ benchmarks:run:cjs /home/runner/work/monorepo/monorepo/packages/http/tools/http-benchmarks
> BUILD_TARGET=cjs ./bin/run-cjs.cjs

[CJS] Running benchmarks...

Express Basic Get Request
┌─────────┬───────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name                 │ Latency avg (ms) │ Latency med (ms) │ Throughput avg (req/s) │ Samples │
├─────────┼───────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼─────────┤
│ 0       │ 'currentInversifyExpress''114.401''46.099''3891.570'             │ 42956   │
│ 1       │ 'express''103.574''44.020''4331.528'             │ 47845   │
│ 2       │ 'NestJSExpress''112.653''45.962''3962.111'             │ 43754   │
└─────────┴───────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴─────────┘
currentInversifyExpress vs express Speedup: 0.898x
currentInversifyExpress vs NestJSExpress Speedup: 0.982x

Express v4 Basic Get Request
┌─────────┬────────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name                  │ Latency avg (ms) │ Latency med (ms) │ Throughput avg (req/s) │ Samples │
├─────────┼────────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼─────────┤
│ 0       │ 'currentInversifyExpress4''100.653''43.196''4460.216'             │ 49251   │
│ 1       │ 'express4''97.554''43.078''4622.143'             │ 51048   │
└─────────┴────────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴─────────┘
currentInversifyExpress4 vs express4 Speedup: 0.965x

Fastify Basic Get Request
┌─────────┬───────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name                 │ Latency avg (ms) │ Latency med (ms) │ Throughput avg (req/s) │ Samples │
├─────────┼───────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼─────────┤
│ 0       │ 'currentInversifyFastify''43.811''37.575''11474.559'            │ 115870  │
│ 1       │ 'fastify''33.784''28.645''14695.451'            │ 148097  │
│ 2       │ 'NestJSFastify''37.745''32.659''13169.053'            │ 132865  │
└─────────┴───────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴─────────┘
currentInversifyFastify vs fastify Speedup: 0.781x
currentInversifyFastify vs NestJSFastify Speedup: 0.871x

Hono Basic Get Request
┌─────────┬────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name              │ Latency avg (ms) │ Latency med (ms) │ Throughput avg (req/s) │ Samples │
├─────────┼────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼─────────┤
│ 0       │ 'currentInversifyHono''39.910''34.775''12486.526'            │ 125989  │
│ 1       │ 'hono''36.646''31.472''13609.447'            │ 137139  │
└─────────┴────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴─────────┘
currentInversifyHono vs hono Speedup: 0.917x

Copy link
Member

@notaphplover notaphplover left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good, but we can add some extra assertions.

I'd love the successful middlerare to set a response header so we can verify in the response the header is set and therefore the middleware was called.

I think the unsuccessful case would be even better if we apply a successful middleware before the unsuccessful one, this way we can detect in the response there's the reponse header and, therefore, middlewares are executed in the right order (if the unsuccessful middleware was executed before, it would send the response so the header wouldn't be there)

@github-actions
Copy link
Contributor

github-actions bot commented May 3, 2025

Benchmarks results:

> root@ benchmarks:http:cjs /home/runner/work/monorepo/monorepo
> pnpm run --filter "@inversifyjs/http-benchmarks" benchmarks:run:cjs


> @inversifyjs/http-benchmarks@ benchmarks:run:cjs /home/runner/work/monorepo/monorepo/packages/http/tools/http-benchmarks
> BUILD_TARGET=cjs ./bin/run-cjs.cjs

[CJS] Running benchmarks...

Express Basic Get Request
┌─────────┬───────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name                 │ Latency avg (ms) │ Latency med (ms) │ Throughput avg (req/s) │ Samples │
├─────────┼───────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼─────────┤
│ 0       │ 'currentInversifyExpress''109.064''43.597''4113.171'             │ 45333   │
│ 1       │ 'express''97.673''42.609''4617.799'             │ 50950   │
│ 2       │ 'NestJSExpress''108.235''44.553''4132.684'             │ 45655   │
└─────────┴───────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴─────────┘
currentInversifyExpress vs express Speedup: 0.891x
currentInversifyExpress vs NestJSExpress Speedup: 0.995x

Express v4 Basic Get Request
┌─────────┬────────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name                  │ Latency avg (ms) │ Latency med (ms) │ Throughput avg (req/s) │ Samples │
├─────────┼────────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼─────────┤
│ 0       │ 'currentInversifyExpress4''96.456''42.464''4680.763'             │ 51634   │
│ 1       │ 'express4''92.502''42.144''4896.223'             │ 54018   │
└─────────┴────────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴─────────┘
currentInversifyExpress4 vs express4 Speedup: 0.956x

Fastify Basic Get Request
┌─────────┬───────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name                 │ Latency avg (ms) │ Latency med (ms) │ Throughput avg (req/s) │ Samples │
├─────────┼───────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼─────────┤
│ 0       │ 'currentInversifyFastify''42.626''35.347''11814.130'            │ 119345  │
│ 1       │ 'fastify''31.533''26.193''15727.908'            │ 158385  │
│ 2       │ 'NestJSFastify''36.107''30.639''13812.031'            │ 139265  │
└─────────┴───────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴─────────┘
currentInversifyFastify vs fastify Speedup: 0.751x
currentInversifyFastify vs NestJSFastify Speedup: 0.855x

Hono Basic Get Request
┌─────────┬────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name              │ Latency avg (ms) │ Latency med (ms) │ Throughput avg (req/s) │ Samples │
├─────────┼────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼─────────┤
│ 0       │ 'currentInversifyHono''39.090''34.326''12873.354'            │ 129865  │
│ 1       │ 'hono''34.691''28.900''14393.419'            │ 145152  │
└─────────┴────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴─────────┘
currentInversifyHono vs hono Speedup: 0.894x

@github-actions
Copy link
Contributor

github-actions bot commented May 3, 2025

Benchmarks results:

> root@ benchmarks:http:cjs /home/runner/work/monorepo/monorepo
> pnpm run --filter "@inversifyjs/http-benchmarks" benchmarks:run:cjs


> @inversifyjs/http-benchmarks@ benchmarks:run:cjs /home/runner/work/monorepo/monorepo/packages/http/tools/http-benchmarks
> BUILD_TARGET=cjs ./bin/run-cjs.cjs

[CJS] Running benchmarks...

Express Basic Get Request
┌─────────┬───────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name                 │ Latency avg (ms) │ Latency med (ms) │ Throughput avg (req/s) │ Samples │
├─────────┼───────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼─────────┤
│ 0       │ 'currentInversifyExpress''105.004''43.769''4259.808'             │ 47084   │
│ 1       │ 'express''95.503''42.110''4714.572'             │ 52108   │
│ 2       │ 'NestJSExpress''104.017''43.898''4302.518'             │ 47563   │
└─────────┴───────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴─────────┘
currentInversifyExpress vs express Speedup: 0.904x
currentInversifyExpress vs NestJSExpress Speedup: 0.990x

Express v4 Basic Get Request
┌─────────┬────────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name                  │ Latency avg (ms) │ Latency med (ms) │ Throughput avg (req/s) │ Samples │
├─────────┼────────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼─────────┤
│ 0       │ 'currentInversifyExpress4''93.090''41.744''4851.450'             │ 53585   │
│ 1       │ 'express4''88.725''40.884''5098.852'             │ 56421   │
└─────────┴────────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴─────────┘
currentInversifyExpress4 vs express4 Speedup: 0.951x

Fastify Basic Get Request
┌─────────┬───────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name                 │ Latency avg (ms) │ Latency med (ms) │ Throughput avg (req/s) │ Samples │
├─────────┼───────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼─────────┤
│ 0       │ 'currentInversifyFastify''41.031''35.382''12317.525'            │ 124151  │
│ 1       │ 'fastify''30.818''25.215''16084.475'            │ 161932  │
│ 2       │ 'NestJSFastify''34.413''29.119''14489.862'            │ 145695  │
└─────────┴───────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴─────────┘
currentInversifyFastify vs fastify Speedup: 0.766x
currentInversifyFastify vs NestJSFastify Speedup: 0.850x

Hono Basic Get Request
┌─────────┬────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name              │ Latency avg (ms) │ Latency med (ms) │ Throughput avg (req/s) │ Samples │
├─────────┼────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼─────────┤
│ 0       │ 'currentInversifyHono''37.258''31.920''13510.149'            │ 136255  │
│ 1       │ 'hono''33.081''27.784''15132.267'            │ 151858  │
└─────────┴────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴─────────┘
currentInversifyHono vs hono Speedup: 0.893x

@notaphplover notaphplover merged commit 78f9492 into main May 3, 2025
9 checks passed
@notaphplover notaphplover deleted the feat/add-middleware-e2e-tests branch May 3, 2025 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants